package Jieyekaoshi2;

import java.util.ArrayList;
import java.util.List;

public class StudentTest {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        //往容器 装三个学生
        //1.容器---->集合---->ArrayList

        students.add(new Student(1, "张三"));
        students.add(new Student(2, "李四"));
        students.add(new Student(3, "王五"));
        //2.数据---->学生对象---->Student
        System.out.println("原始学生列表：");
        for (Student student : students) {
            System.out.println(student);
        }
        //修改一个
        for (Student student : students) {
            if ("张三".equals(student.getName())) {
                student.setName("张三丰");
                break;
            }
        }

        //找到张三
        System.out.println("修改张三姓名后的学生列表：");
        for (Student student : students) {
            System.out.println(student);
        }
        //删除一个
        for (int i = 0; i < students.size(); i++) {
            if ("王五".equals(students.get(i).getName())) {
                students.remove(i);
                break;
            }
        }


        System.out.println("删除王五后的学生列表：");
        for (Student student : students) {
            System.out.println(student);
        }

    }
}
